﻿//
// 请注意：bbsmax 不是一个免费产品，源代码仅限用于学习，禁止用于商业站点或者其他商业用途
// 如果您要将bbsmax用于商业用途，需要从官方购买商业授权，得到授权后可以基于源代码二次开发
//
// 版权所有 厦门麦斯网络科技有限公司
// 公司网站 www.bbsmax.com
//

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using MaxLabs.WebEngine;
using MaxLabs.bbsMax.Entities;

namespace MaxLabs.bbsMax.Web.max_dialogs
{
    public partial class doing_delete : DialogPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_Request.IsClick("delete"))
            {
                doingID = _Request.Get<int>("id", Method.Get);

                if (doingID.HasValue == false)
                    ShowError("缺少必要参数");

                Doing doing = DoingBO.Instance.GetDoingForDelete(MyUserID, doingID.Value);

                if (doing == null)
                    ShowError("您要删除的记录不存在");

                Delete();
            }
        }

        protected override bool EnableClientBuffer
        {
            get
            {
                return false;
            }
        }

        int? doingID = null;

        private void Delete()
        {
            bool success = false;

            MessageDisplay msgDisplay = CreateMessageDisplay();

            using (ErrorScope es = new ErrorScope())
            {
                try
                {
                    success = DoingBO.Instance.DeleteDoing(MyUserID, doingID.Value);
                }
                catch (Exception ex)
                {
                    msgDisplay.AddException(ex);
                }
 
                if (success == false)
                {
                    es.CatchError<ErrorInfo>(delegate(ErrorInfo error)
                    {
                        msgDisplay.AddError(error);
                    });
                }
            }

            if (success)
                Return("id", doingID);
        }
    }
}